// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) definits fieldsfirst ansi space safe 
// Source File Name:   SimpleSimulation.java

package jones;

import java.util.*;
import jones.rigid.RigidBody;

// Referenced classes of package jones:
//            World, SimpleSimulator, SimObject, Light, 
//            Simulation, Simulator

public abstract class SimpleSimulation
    implements Simulation
{

    protected List robots = null;
    protected List rigidBodies = null;
    protected List lights = null;
    protected List simObjects = null;
    protected Set observables = null;
    protected World world = null;
    protected Simulator simulator = null;

    public SimpleSimulation()
    {
        robots = ((List) (new ArrayList()));
        rigidBodies = ((List) (new ArrayList()));
        lights = ((List) (new ArrayList()));
        simObjects = ((List) (new ArrayList()));
        observables = ((Set) (new HashSet()));
        world = new World();
        simulator = ((Simulator) (new SimpleSimulator()));
    }

    protected void initSimulation()
    {
        initLights();
        initRobots();
        initRigidBodies();
        initSimObjects();
        initObservables();
        initWorld();
        initSimulator();
    }

    protected void initLights()
    {
    }

    protected void initRobots()
    {
    }

    protected void initRigidBodies()
    {
        rigidBodies.addAll(((java.util.Collection) (robots)));
    }

    protected void initSimObjects()
    {
        simObjects.addAll(((java.util.Collection) (robots)));
    }

    protected void initObservables()
    {
        observables.addAll(((java.util.Collection) (rigidBodies)));
        observables.addAll(((java.util.Collection) (simObjects)));
        observables.addAll(((java.util.Collection) (lights)));
    }

    protected void initWorld()
    {
        for (Iterator i = rigidBodies.iterator(); i.hasNext(); world.addRigidBody((RigidBody)i.next()));
        for (Iterator i = simObjects.iterator(); i.hasNext(); world.addSimObject((SimObject)i.next()));
        for (Iterator i = lights.iterator(); i.hasNext(); world.addLight((Light)i.next()));
    }

    protected void initSimulator()
    {
        simulator.addSimObject(((SimObject) (world)));
        for (Iterator i = observables.iterator(); i.hasNext(); simulator.addObservable((Observable)i.next()));
    }

    public World getWorld()
    {
        return world;
    }

    public Simulator getSimulator()
    {
        return simulator;
    }

    public Observable[] getObservables()
    {
        return (Observable[])observables.toArray(((Object []) (new Observable[0])));
    }

    public void removeObservable(Observable observable)
    {
        robots.remove(((Object) (observable)));
        rigidBodies.remove(((Object) (observable)));
        simObjects.remove(((Object) (observable)));
        lights.remove(((Object) (observable)));
        observables.remove(((Object) (observable)));
        if (observable instanceof RigidBody)
            world.removeRigidBody((RigidBody)observable);
        if (observable instanceof SimObject)
            world.removeSimObject((SimObject)observable);
        if (observable instanceof Light)
            world.removeLight((Light)observable);
        simulator.removeObservable(observable);
    }
}
